Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for empty result set with selectOne #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dpetran
Copy link
Contributor

@dpetran dpetran commented Jan 20, 2025

I've mapped a nil result when a selectOne query returns no results to the JSON string "null", which parses to null in Javascript. Without this support the response fails to conform to the QueryResponse schema.

@dpetran dpetran requested a review from a team January 20, 2025 20:42
(fn [handler]
(fn [req]
(let [{:keys [status body] :as result} (handler req)]
(if (and (= 200 status) (nil? body))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something that should be handled by muuntaja instead of rolling our own conversion for this specific case. Is there no way to accomplish this using that library since we're already using it to convert between formats? I can see this causing issues if we ever decide to respond with edn as well as json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it an honest try with muuntaja but wasn't willing to devote more than 2 hours to it. Once I couldn't get it working in that window I went back to this. I figure that if we ever do support edn there will need to be a lot of updates to the middleware anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a problem with the QureryResponse schema? What happens when you just account for the possibility that :select-one query responses can also be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it converts the :body key to the empty string "", which isn't valid json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants